#点击商品链接
clickGoods = (sellername,maxSearchPage,again=on)->
	sellers = document.querySelectorAll('.item-box .seller a')
	find = off
	currentPage = $('.pagination span.page-cur').html()
	for v in sellers
		if sellername == v.innerHTML
			console.debug 'finded'
			find = on
			target = v.parentNode.parentNode.parentNode.parentNode.querySelector('.pic-box a')
			target.setAttribute 'target','_self'
			target.focus()
			target = target.querySelector('img')
			simulateClick target,{ctrl:on}
			setTimeout window.close,10000+Math.ceil(Math.random()*50*1000)
			#设置心跳,返回页码
			messenger.findPage currentPage
			messenger.stop()
			break
	console.debug 'no find'
	unless find
		if again
			#第一次没有找到，过10秒再找一次
			setTimeout(->
				clickGoods sellername,maxSearchPage,off
			,10000)
		else
			nextPageDom = $('.page-siblings .page-next')[0]
			if 0 < currentPage <= maxSearchPage and nextPageDom
				simulateClick nextPageDom
			else
				#没有找到进入下一个搜索
				messenger.postPage -1
				messenger.next()
			messenger.stop()



#得到商家Id
chrome.extension.sendRequest {searchData:1,maxSearchPage:1},(response)->
	messenger.start(30)
	document.body.scrollTop += 1600
	setTimeout ->
		if response && response.searchData
			clickGoods response.searchData.sellername,response.maxSearchPage
	,9100
